<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>Ic卡信息录入</title>

</head>
<body>
	<script type="text/javascript"> 
	
	 //显示卡号
	
	$.extend($.fn.validatebox.defaults.rules, {
		Chackiccard: {
	        validator: function(value){        	
	        	var myreg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	        	  if( myreg.test(value)){
	        			var pdsex;
	        			if (parseInt(value.substr(16, 1)) % 2 == 1) { 
	        				pdsex='男'; 
	        				$("#iSex").textbox("setValue",pdsex );

	        			} else { 
	        				pdsex='女'; 
	        				$("#iSex").textbox("setValue",pdsex );
	        			} 
	
	        			//获取年龄 
	        			var myDate = new Date(); 
	        			var month = myDate.getMonth() + 1; 
	        			var day = myDate.getDate(); 
	        			var age = myDate.getFullYear() - value.substring(6, 10) - 1; 
	        			if (value.substring(10, 12) < month || value.substring(10, 12) == month && value.substring(12, 14) <= day) { 
	        			age++; 
	        			} 
	        			$("#iAge").textbox("setValue",age );      			
	        			 //定义地区数组  
	        			 var CityArray = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 
				        				   31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 
				        				   43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 
				        				   61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" 
				        				 }
	        			if (CityArray[parseInt(value.substr(0, 2))]==null){
	        				$("#iAddress").textbox("setValue","非法地区"); 	        				 				
	        			}else{
	        				$("#iAddress").textbox("setValue",CityArray[parseInt(value.substr(0, 2))] ); 	        				
	        			} 
	        		  return true;
	        	  }else{
	        		  return false;
	        	  }
	        	   
	        },
	        message: '身份证号码有误！！'
	    }
	});
	
	$.extend($.fn.validatebox.defaults.rules, {
		Chackpho: {
	        validator: function(value){
	        	  var myreg =/^1[34578]\d{9}$/;
	        	  if( myreg.test(value)){    		  
	        		  return true;
	        	  }else{
	        		  return false;
	        	  }
	        	   
	        },
	        message: '电话号码有误！！'
	    }
	});
	
		$(function(){
			var date = new Date();		
			var y = date.getFullYear();  
			var m = date.getMonth() + 1;  
			m = m < 10 ? '0' + m : m;  
			var d = date.getDate();  
			d = d < 10 ? ('0' + d) : d;  
			var needDate=y + '-' + m + '-' + d;  	
			 
			$("#stuadd").linkbutton({
				onClick:function(){
					$('#stuwin').window({'title': "开户信息录入"});
					$("#stuwin").window('open');
					$("#stuff").form("clear");
					$("#iOpenTime").textbox("setValue",needDate);
					$.ajax({
					        type: "Post",
					        url: "findMaxStuByPage",
					        data: {},
					        success: function (data) {
					        	var idcardnum=data+1;
					        	$("#idcardnum").textbox("setValue",idcardnum); 	        				
					        },
					});
				}
			});
			$("#stu-save").linkbutton({  
				onClick : function() {
					var text = $('#iIdentityCard').textbox('getValue');
					$('#stuff').form('submit', {
						onSubmit : function() {
						},				
						success : function(data) {
							var json = eval("("+data+")");
							$.messager.alert("温馨提示", json.reason);			
							$("#stutab").datagrid({
							       rowStyler: function (index, row) {
							            if (row.iIdentityCard== text) {
							                 return 'background-color:#6293BB;color:#fff;';
							            }
							       }
							}); 
							//关闭窗口
							$("#stuwin").window('close');
							//重新加载数据
							$("#stutab").datagrid("reload");
							$(this).form("clear");
						}
					});
				}
			});
						
			$("#stucancel").linkbutton({
				onClick : function() {
					$('#stuff').form("clear");
					$("#stuwin").window("close");
				}
			});
			$("#ref").linkbutton({
				onClick:function(){	
					
					$("#stutab").datagrid({
						 url: 'topage'
					});
				}
			});
			$('#search').searchbox({
			    searcher:function(value,name){
			    	if(name=="性别"){
			    		$("#stutab").datagrid({
				    		url:'findbySex',
				    		queryParams: {
				    			sex: value
				    		}
				    	});
			    	}else if(name=="姓名"){
			    		$("#stutab").datagrid({
				    		url:'findbyname',
				    		queryParams: {
				    			sex: value
				    		}
				    	});
			    	}else if(name=="地址"){
			    		$("#stutab").datagrid({
				    		url:'findbySaddress',
				    		queryParams: {
				    			sex: value
				    		}
				    	});
			    	}else if(name=="身份证号码"){
			    		$("#stutab").datagrid({
				    		url:'findbyiccard',
				    		queryParams: {
				    			sex: value
				    		}
				    	});
			    	}			    	
			    	
			    }
			});
		});
	</script>
	
	<table id="stutab" class="easyui-datagrid"
			data-options="
				fitColumns:true,
				fit:true,
				rownumbers: true,
			    url: 'topage',
				border:false ,
				pagination:true,
				toolbar: '#jl_btn',
				pageSize: 15,
				pageList:[15,25,35,45]
			">
			<thead>
				<tr>
					<th class="ident" data-options="field:'iId'">Ic卡号</th>
					<th class="ident" data-options="field:'iName',width:10">持卡者姓名</th>
					<th class="ident" data-options="field:'iIdentityCard',width:15,editor:'textbox'">身份证号码</th>
					<th class="ident" data-options="field:'iAge'">持卡者年龄</th>
					<th class="ident" data-options="field:'iSex'">持卡者性别</th>
					<th class="ident" data-options="field:'iAddress',width:15,">家庭地址</th>
					<th class="ident" data-options="field:'iPho',width:10,">联系电话</th>
					<th class="ident" data-options="field:'iOpenTime',width:10,formatter:function(value){
                          var unixTimestamp = new Date(value);  
                          return unixTimestamp.toLocaleDateString();}">开户日期
                    </th> 
				</tr>
			</thead>
		</table>
	
	<div id="jl_btn">
		<a id="stuadd" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">Ic卡开户</a> 
		<a id="ref"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">显示全部记录</a>
		<input id="search" class="easyui-searchbox" 
			data-options="menu:'#ee',width:220,prompt:'请输入。。。。'">
	</div>
	<div id="ee" style=" width:90px">
		<div date-options="name:'name'">性别</div>
		<div date-options="name:'name'">姓名</div>
		<div date-options="name:'name'">地址</div>
		<div date-options="name:'name'">身份证号码</div>
	</div>
	<div>
		<div id="stuwin" class="easyui-window"
			style="padding: 10px;line-height: 150%;"
			data-options="
		     width: 450,
		     height:204,
		     closed: true
			">		
				<form id="stuff" action="addIc" method="post">
					<table>
						<tr>
							<td>
								<div class="item">
									<input id="idcardnum"   ReadOnly="readonly"class="easyui-textbox" data-options="label: '卡&nbsp;&nbsp;号:', width: 200,labelWidth:65">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="iOpenTime" ReadOnly="readonly" name="iOpenTime" type="text" class="easyui-textbox"  data-options="label: '开户日期:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
								<input id="iName" required="required" name="iName" class="easyui-textbox" data-options="label: '用户姓名:', width: 200,labelWidth:65">									
								</div>
							</td>
							<td>
							    <div class="item">
									<input id="iAge" name="iAge" ReadOnly="readonly" class="easyui-textbox" data-options="label: '用户年龄:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
							   <div class="item">
							   <input id="iIdentityCard"  required="required" name="iIdentityCard" class="easyui-textbox" data-options="label: '身份证号:',validType: ['Chackiccard'], width: 200,labelWidth:65">									
								</div>
							</td>
							<td>						
								 <div class="item">
									<input id="iSex" name="iSex" ReadOnly="readonly" class="easyui-textbox" data-options="label: '用户性别:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
									<input id="iPho" name="iPho" required="required" class="easyui-textbox" data-options="label: '联系电话:', validType: ['Chackpho'], width: 200,labelWidth:65">
								</div>
							</td>
							<td>
								 <div class="item">
									<input id="iAddress"  name="iAddress" ReadOnly="readonly" class="easyui-textbox" data-options="label: '家庭地址:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
									
								</div>
							</td>
							<td>
								<div class="item">
									<a id="stu-save" class="easyui-linkbutton" data-options="iconCls:'icon-icNo'"style="width:90px">确定</a>
									<a id="stucancel" class="easyui-linkbutton" data-options="iconCls:'icon-icOk'"style="width:90px;margin-left:12px;">取消</a>
								</div>
							</td>
						</tr>
					</table>	
				</form>
			
		</div>
	</div>
</body>
</html>